<?php 
	session_start();
	require_once("../includes/public.inc.php");
	$type = isset($_GET['type'])?$_GET['type']:'';
	$username = isset($_SESSION['username'])?$_SESSION['username']:'';
	if (empty($username))
	{
		echo "<script>alert('亲你还没有登录哦');history.back();</script>";	exit;
	}
	//$type = isset($_GET['type'])?$_GET['type']:'';
	$act = isset($_GET['act'])?$_GET['act']:'';
	$pass = isset($_POST['pass'])?$_POST['pass']:'';
	$newpass = isset($_POST['new_pass'])?$_POST['new_pass']:'';
	$againpass = isset($_POST['new_pass2'])?$_POST['new_pass2']:'';
	if ($againpass != $newpass)
	{
		echo"<script>alert('两次输入的密码不一致！');history.go(-1);</script>";exit;
	}
	if ($username)
	{
		if ($act == 'save')
		{
			if ($type=='dg')
			{
				$user = mysql_fetch_array(mysql_query("select * from ".DBQIAN."daogou where username='".trim($username)."' and password='".trim($pass)."' order by id desc limit 1"));
				//print_r("select * from ".DBQIAN."daogou where username='".trim($username)."' and password='".trim($pass)."' order by id desc limit 1");exit;
				if ($user)
				{
					$result = mysql_query("update ".DBQIAN."daogou set password='".$newpass."' where username='".$username."'");
					if ($result)
					{
						echo"<script>alert('修改成功');window.location.href='login.php?type=".$type."';</script>";  
					}
					else 
					{
						echo"<script>alert('修改失败');history.go(-1);</script>";
					}
				}
				else 
				{
					echo"<script>alert('修改失败,密码不正确！');history.go(-1);</script>";  	
				}
			}
			else 
			{
				$user = mysql_fetch_array(mysql_query("select * from ".DBQIAN."users where username='".$username."' and password='".$pass."' order by id desc limit 1"));
				if ($user)
				{
					$result = mysql_query("update ".DBQIAN."users set password='".$newpass."' where username='".$username."'");
					if ($result)
					{
						echo"<script>alert('修改成功');window.location.href='login.php?type=".$type."';</script>"; 
					}
					else 
					{
						echo"<script>alert('修改失败');history.go(-1);</script>";
					}
				}
				else 
				{
					echo"<script>alert('修改失败，密码不正确！');history.go(-1);</script>";  	
				}
			}
		}
		else 
		{
			echo"<script>alert('修改失败!');history.go(-1);</script>";
		}
	}
	else 
	{
		echo"<script>alert('修改失败,你还没登录呢!');history.go(-1);</script>";
	}
?>
